<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2018/1/17 0017
  Time: 下午 4:03
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>${sessionScope.title}</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="/admin/css/x-admin.css" media="all">
    <link rel="stylesheet" href="/js/layui/css/layui.css" media="all">
</head>
<body>
<div class="x-nav">
            <span class="layui-breadcrumb">
              <a><cite>首页</cite></a>
              <a><cite>会员管理</cite></a>
              <a><cite>权限分类</cite></a>
            </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"  href="javascript:location.replace(location.href);" title="刷新"><i class="layui-icon" style="line-height:30px">ဂ</i></a>
</div>
<div class="x-body">
    <form class="layui-form x-center" action="" style="width:40%">
        <input type="hidden" name="id" value="">
        <div class="layui-form-pane" style="margin-top: 15px;">
            <div class="layui-form-item">
                <label class="layui-form-label">分类名</label>
                <div class="layui-input-inline">
                    <input type="text" name="name"  placeholder="分类名" autocomplete="off" class="layui-input">
                </div>
                <div class="layui-input-inline" style="width:80px">
                    <button class="layui-btn"  lay-submit="" lay-filter="/adminSystem/saveRpermissionType"><i class="layui-icon">&#xe608;</i>添加</button>
                </div>
            </div>
        </div>
    </form>
    <xblock><button class="layui-btn layui-btn-danger" onclick="delAll()"><i class="layui-icon">&#xe640;</i>批量删除</button><span class="x-right" style="line-height:40px">共有数据：88 条</span></xblock>
    <table class="layui-table">
        <thead>
        <tr>
            <th>
                <input type="checkbox" name="" value="">
            </th>
            <th>
                ID
            </th>
            <th>
                分类名
            </th>
            <th>
                操作
            </th>
        </tr>
        </thead>
        <tbody id="x-link">
        <c:forEach items="${returnData}" var="rda">
        <tr>
            <td>
                <input type="checkbox" value="1" name="">
            </td>
            <td>
                ${rda.id}
            </td>
            <td>
                    ${rda.type_name}
            </td>
            <td class="td-manage">
                <a title="编辑" href="javascript:;" onclick="cate_edit('编辑','/adminSystem/toRpermissionType','${rda.id}','','510')"
                   class="ml-5" style="text-decoration:none">
                    <i class="layui-icon">&#xe642;</i>
                </a>
                <a title="删除" href="javascript:;"
                   onclick="cate_del(this,'${rda.id}')"
                   style="text-decoration:none">
                    <i class="layui-icon">&#xe640;</i>
                </a>
            </td>
        </tr>
        </c:forEach>
        </tbody>
    </table>

    <div id="page"></div>
</div>
<script src="/js/layui/layui.all.js" charset="utf-8"></script>

<script src="/admin/js/x-layui.js" charset="utf-8"></script>
<script src="/admin/js/jquery.min.js" charset="utf-8"></script>
<script>


    layui.use(['element'], function(){
        $ = layui.jquery;
       var element = layui.element;

        //导航的hover效果、二级菜单等功能，需要依赖element模块
        // larry-side-menu向左折叠
        if($(window).width()<750){
            trun = 0;
        }else{
            trun = 1;
        }

        $('.larry-side-menu').click(function() {
            if(trun){
                $('.x-side').animate({left: '0px'},200).siblings('.x-main').animate({left: '200px'},200);
                trun=0;
            }else{
                $('.x-side').animate({left: '-200px'},200).siblings('.x-main').animate({left: '0px'},200);
                trun=1;
            }

        });



        //监听导航点击
        element.on('nav(side)', function(elem){
            title = elem.find('cite').text();
            url = elem.find('a').attr('_href');
            // alert(url);

            for (var i = 0; i <$('.x-iframe').length; i++) {
                if($('.x-iframe').eq(i).attr('src')==url){
                    element.tabChange('x-tab', i);
                    return;
                }
            };

            res = element.tabAdd('x-tab', {
                title: title//用于演示
                ,content: '<iframe frameborder="0" src="'+url+'" class="x-iframe"></iframe>'
            });


            element.tabChange('x-tab', $('.layui-tab-title li').length-1);

            $('.layui-tab-title li').eq(0).find('i').remove();
        });
    });





    layui.use('form', function(){
        layer = layui.layer;//弹出层
        var form = layui.form;//弹出层
        //监听提交
        form.on('submit(/adminSystem/saveRpermissionType)', function(data){
            //layer.msg(data.field);
            console.log(data.field);
            //发异步，把数据提交给php
            $.ajax({
                url:'/adminSystem/saveRpermissionType',
                type:'POST', //GET
                async:true,    //或false,是否异步
                data:data.field,
                timeout:5000,    //超时时间
                dataType:'json',    //返回的数据格式：json/xml/html/script/jsonp/text
                beforeSend:function(xhr){
                    /*console.log(xhr)
                     console.log('发送前')*/
                },
                success:function(retdata){
                    layer.alert("增加成功", {icon: 6});
                    $('#x-link').prepend('<tr><td><input type="checkbox"value="1"name=""></td><td>1</td><td>'
                        +data.field.name+'</td><td class="td-manage">' +
                        '<a title="编辑"href="javascript:;"onclick="cate_edit(\'编辑\',\'/adminSystem/toRpermissionType\',\'' +data.field.id+
                        '\',\'\',\'510\')"' +
                        'class="ml-5"style="text-decoration:none"><i class="layui-icon">&#xe642;</i></a>' +
                        '<a title="删除"href="javascript:;"onclick="cate_del(this,\'' +retdata.data.id+
                        '\')"style="text-decoration:none">' +
                        '<i class="layui-icon">&#xe640;</i></a></td></tr>');
                    console.log(data);
                    return false;
                },
                error:function(xhr,textStatus){
                    console.log('错误')
                    console.log(xhr)
                    console.log(textStatus)
                },
                complete:function(){
                    return false;
                    //console.log('结束')
                }
            });
            return false;
        });
    });

    //以上模块根据需要引入

    //批量删除提交
    function delAll () {
        layer.confirm('确认要删除吗？',function(index){
            //捉到所有被选中的，发异步进行删除
            layer.msg('删除成功', {icon: 1});
        });
    }



    //-编辑
    function cate_edit (title,url,id,w,h) {
        console.log("title:"+title+"url:"+url+"id:"+id);
        url+="?id="+id;
        x_admin_show(title,url,w,h);
    }

    /*删除*/
    function cate_del(obj,id){
        console.log("数据ID为："+id)
        layer.confirm('确认要删除吗？',function(index){
            //发异步删除数据
            $.ajax({
                url:'/adminSystem/delRpermissionType',
                type:'POST', //GET
                async:true,    //或false,是否异步
                data:{
                    id:id
                },
                timeout:5000,    //超时时间
                dataType:'json',    //返回的数据格式：json/xml/html/script/jsonp/text
                beforeSend:function(xhr){
                    /*console.log(xhr)
                     console.log('发送前')*/
                },
                success:function(redata){
                    console.log(redata);
                    console.log(redata.data);
                    if (redata.data==1){
                        $(obj).parents("tr").remove();
                        layer.msg('已删除!',{icon:1,time:1000});
                    }else {
                        layer.msg('删除失败!',{icon:5,time:1000});
                    }

                },
                error:function(xhr,textStatus){
                    console.log('错误')
                    console.log(xhr)
                    console.log(textStatus)
                },
                complete:function(){
                    //console.log('结束')
                }
            });
        });
    }
</script>

</body>
</html>
